package co.yixiang.retail.biz.order.mapper;

import co.yixiang.common.mproot.common.mapper.CoreMapper;
import co.yixiang.mall.common.order.dto.YxStoreOrderQueryCriteria;
import co.yixiang.retail.common.domain.YxExpress;
import co.yixiang.retail.common.domain.YxStoreOrder;
import co.yixiang.retail.common.dto.YsStoreOrderSalesDetailDto;
import co.yixiang.retail.common.dto.YxStoreOrderSalesDetailQueryCriteria;
import co.yixiang.retail.common.dto.YxStoreOrderShipmentsDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface YxStoreOrderMapper extends CoreMapper<YxStoreOrder> {
    List<YxStoreOrder> queryByUserId(YxStoreOrderQueryCriteria yxStoreOrderQueryCriteria);

    @Select("<script> select yx_store_order.status," +
            "yx_store_order.order_id," +
            "yx_store_order.user_phone,"+
            "yx_store_order.pay_type," +
            "yx_store_order.shipping_type," +
            "yx_store_order.delivery_id," +
            "yx_user.nickname," +
            "yx_store_order.real_name," +
            "yx_store_order.user_address," +
            "yx_store_order.mark," +
            "yx_store_order.remark," +
            "yx_store_product_attr_value.image," +
            "yx_store_product.store_name," +
            "yx_store_product_attr_value.price," +
            "yx_store_product_attr_value.sku," +
            "yx_store_order_attr_value.amount," +
            "yx_store_order.total_price," +
            "yx_store_order.freight_price," +
            "yx_store_order.pay_price " +
            "from " +
            "yx_store_order " +
            "LEFT JOIN yx_store_order_attr_value ON yx_store_order.id = yx_store_order_attr_value.oid " +
            "LEFT JOIN yx_store_product on yx_store_product.id = yx_store_order_attr_value.product_id " +
            "LEFT JOIN yx_user ON yx_store_order.uid = yx_user.uid " +
            "LEFT JOIN yx_store_product_attr_value ON yx_store_order_attr_value.sku_id = yx_store_product_attr_value.id " +
            "where 1=1 and " +
            "yx_store_order.id = #{criteria.id} and " +
            "yx_store_order.pay_type = #{criteria.payType}" +
            " <if test =\"criteria.isBatch !=null and criteria.isBatch!='' \"> and yx_store_order.is_batch = #{criteria.isBatch} </if></script>")
    List<YsStoreOrderSalesDetailDto> queryById(@Param("criteria") YxStoreOrderSalesDetailQueryCriteria criteria);


    @Select("<script> select yx_store_order_attr_value.amount," +
            "yx_store_product.id as productId," +
            "yx_store_product_attr_value.id as skuId " +
            "from " +
            "yx_store_order " +
            "LEFT JOIN yx_store_order_attr_value ON yx_store_order.id = yx_store_order_attr_value.oid " +
            "LEFT JOIN yx_store_product on yx_store_product.id = yx_store_order_attr_value.product_id " +
            "LEFT JOIN yx_user ON yx_store_order.uid = yx_user.uid " +
            "LEFT JOIN yx_store_product_attr_value ON yx_store_order_attr_value.sku_id = yx_store_product_attr_value.id " +
            "where 1=1 and " +
            "yx_store_order.id = #{cmd.id} and " +
            "yx_store_order.pay_type = #{cmd.payType}" +
            " <if test =\"cmd.isBatch !=null and cmd.isBatch!='' \"> and yx_store_order.is_batch = #{cmd.isBatch} </if></script>")
    List<YsStoreOrderSalesDetailDto> query(@Param("cmd") YxStoreOrderShipmentsDto cmd);
    @Select("select nickName from yx_user where uid = #{uid}")
    String queryNick(Long uid);
}
